package net.nio;

import java.nio.IntBuffer;
import java.util.stream.IntStream;

/**
 * 缓冲区buffer练习
 *
 * @author 王霄
 * @date 2021/8/21 16:23
 */
public class Buffer_ {
    public static void main(String[] args) {

        //private int mark = -1;
        //private int position = 0;
        //private int limit;
        //private int capacity;


        //创建一个buffer,容量为5
        var intBuffer = IntBuffer.allocate(5);
        IntStream.range(0, intBuffer.capacity()).forEach(intBuffer::put);

        //读写切换，从buffer中取数据
        intBuffer.flip();
        while (intBuffer.hasRemaining()) {
            System.out.println(intBuffer.get());
        }
    }
}
